#!/usr/bin/env python
# -*- coding:utf8 -*-
from scrapy import Field

from squirrel_core.commons.seed import CRAWL_COUNTER, PAYLOAD, SEED_KEY, CRAWL_STATUS
from squirrel_core.item.seed_item import SeedItem

__all__ = ["FailedSeedItem"]


class FailedSeedItem(SeedItem):
    seed_status = Field()

    def process_item(self, *args, **kwargs):
        """
            pop seed data to outside dict and return dict
        Args:
            *args:
            **kwargs:
        Returns:
            dict value
        """
        item_dict = dict(self)
        seed_data = item_dict.get("seed_data", {})
        ret = {"table_name": "{}_{}".format(seed_data.get(SEED_KEY), item_dict.get(CRAWL_STATUS)),
               CRAWL_COUNTER: int(seed_data.get(CRAWL_COUNTER, 0)),
               PAYLOAD: seed_data.get(PAYLOAD)}
        return ret
